# coding: utf-8
import os
import pymongo
from ris_tag.model.base import Base

class Tags(Base):
    def __init__(self):
        super(Tags, self).__init__()
        self.collection = self.db['tags']

    def find(self, query):
        result = self.collection.find(query)
        return list(result)

    def find_detail(self):
        result = self.collection.aggregate([
            {'$match': {'creator': 'system'}},
            {'$group': {
                '_id': '$name',
                'name': {'$last': '$name'},
                'description': {'$last': '$description'},
                'level': {'$last': '$level'}
            }},
            {'$project': {
                '_id': 0,
                'name': '$name',
                'description': '$description',
                'level': '$level'
            }}
        ])
        return list(result)



if __name__ == '__main__':
    tags = Tags()
    data = tags.find_detail()
    print(data)
